package com.zlq.cn.controller.sign.movie;


import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.cache.RedisCacheService;
import com.zlq.cn.dto.param.MovieLoginParam;
import com.zlq.cn.dto.param.MovieRegisterParam;
import com.zlq.cn.dto.param.SendSmsParam;
import com.zlq.cn.dto.vo.SignCommonParam;
import com.zlq.cn.entity.User;
import com.zlq.cn.service.movie.MovieUserService;
import com.zlq.cn.service.un.SmsRecordService;
import com.zlq.cn.service.un.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 影片用户 前端控制器
 * </p>
 *
 * @author zhoucl
 * @since 2022-03-19
 */
@Slf4j
@Api(tags = "影片-用户")
@RestController
@RequestMapping("/movie/user")
public class MovieUserController {

    @Resource
    private UserService userService;

    @Resource
    private MovieUserService movieUserService;

    @Resource
    private SmsRecordService smsRecordService;

    @Resource
    private RedisCacheService redisCacheService;

    @ApiOperation("用户登录-ios")
    @PostMapping("/login/ios")
    public SignApiResult<User> loginIos(@RequestBody MovieLoginParam param) {
        return SignApiResult.resultSuccess(movieUserService.loginIos(param));
    }

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public SignApiResult<User> login(@Valid @RequestBody MovieLoginParam param) {
        return SignApiResult.resultSuccess(movieUserService.login(param));
    }

    @ApiOperation("用户注册")
    @PostMapping("/register")
    public SignApiResult<Boolean> register(@Valid @RequestBody MovieRegisterParam param) {
        return SignApiResult.resultSuccess(movieUserService.register(param));
    }

    @ApiOperation("用户注销")
    @PostMapping("/logOff")
    public SignApiResult<Boolean> logOff(@RequestBody SignCommonParam signCommonParam) {
        return SignApiResult.resultSuccess(movieUserService.logOff());
    }

    @ApiOperation("修改头像/昵称")
    @PostMapping("/update/info")
    public SignApiResult<String> updateUserInfo(@RequestBody User user) {
        userService.updateUserAvatarAndNameAndGender(user);
        return SignApiResult.resultSuccess("修改成功");
    }

    @ApiOperation("发送短信")
    @PostMapping("/send/sms")
    public SignApiResult<String> sendSms(@Valid @RequestBody SendSmsParam sendSmsParam) throws Exception {
        smsRecordService.sendSmsCheckImei(sendSmsParam);
        return SignApiResult.resultSuccess("发送成功");
    }
}

